<template id="che">
  <div>
    <el-input style="width: 25%;" v-model="itemName" placeholder="请输入名称"></el-input>
        &nbsp;&nbsp;
        <el-button style="width: 15%;" @click="queryAll" type="primary">查询</el-button>
        <el-button style="width: 15%;" @click="kk=true"  type="primary">添加</el-button>
        <el-table :data="list">
        <el-table-column prop="id" label="编号"> 
        </el-table-column>
        <el-table-column prop="bh" label="编码">
        </el-table-column>
        <el-table-column prop="itemname" label="检查项名称">
        </el-table-column>
        <el-table-column prop="type" label="项目类型">
        </el-table-column>
        <el-table-column prop="sex" label="适用性别">
            <template slot-scope="scope">
              {{ scope.row.sex==0?"不限"
                :scope.row.sex==1?"男":"女"
               }}
          </template>
        </el-table-column>
        <el-table-column prop="" label="适用年龄">
            <template slot-scope="scope">
                <span>
                    {{ scope.row.minage }}-{{ scope.row.maxage }}
                </span>
            </template>
        </el-table-column>
        <el-table-column prop="price" label="价格">
        </el-table-column>
        <el-table-column prop="item" label="项目说明">
        </el-table-column>
        <el-table-column prop="zysx" label="注意事项">
        </el-table-column>
        <el-table-column prop="classify" label="所属分类">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="primary"  icon="el-icon-edit" @click="queryId(scope.row.id),up=true"  circle></el-button>
            <el-popconfirm @confirm="del(scope.row.id)" title="这是一段内容确定删除吗">
            <el-button type="danger" slot="reference" icon="el-icon-delete" circle></el-button>
          </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[3, 5, 7, 10]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

    <!--添加-->
    <el-dialog
    title="添加"
    :visible.sync="kk"
    width="30%"
    center>
    <el-form :model="che" status-icon  ref="che" label-width="100px" class="demo-ruleForm">
    项目名称:<el-input v-model="che.itemname" style="width: 80%;"/><br>
    <h1></h1>
    适用性别:<el-select v-model="che.sex" style="width: 80%;">
      <el-option label="不限" value="0"></el-option>
      <el-option label="男" value="1"></el-option>
      <el-option label="女" value="2"></el-option>
    </el-select><br>
    <h1></h1>
    年龄下限:<el-input v-model="che.minage" style="width: 80%;"/><br>
    <h1></h1>
    年龄上限:<el-input v-model="che.maxage" style="width: 80%;"/><br>
    <h1></h1>
    项目价格:<el-input v-model="che.price" style="width: 80%;"></el-input><br>
    <h1></h1>
    项目类别:<el-input v-model="che.type" style="width: 80%;"></el-input><br>
    <h1></h1>
    所属分类:<el-input v-model="che.classify" style="width: 80%;"></el-input><br>
    <h1></h1>
    项目说明:<el-input v-model="che.item" style="width: 80%;"></el-input><br>
    <h1></h1>
    注意事项:<el-input v-model="che.zysx" style="width: 80%;"></el-input><br>
    <h1></h1>
  
    <el-button @click="reset('motion'),kk = false">取 消</el-button>
    <el-button type="primary" @click="kk = false,add()" >确 定</el-button>
  </el-form>
  </el-dialog>


  <!--修改-->
  <el-dialog
    title="修改"
    :visible.sync="up"
    width="30%"
    center>
    <el-form :model="che" status-icon  ref="che" label-width="100px" class="demo-ruleForm">
      <input v-model="ches.id" type="hidden"/>
    项目名称:<el-input v-model="ches.itemname" style="width: 80%;"/><br>
    <h1></h1>
    适用性别:<el-select v-model="ches.sex" style="width: 80%;">
      <el-option label="不限" value="0"></el-option>
      <el-option label="男" value="1"></el-option>
      <el-option label="女" value="2"></el-option>
    </el-select><br>
    <h1></h1>
    年龄下限:<el-input v-model="ches.minage" style="width: 80%;"/><br>
    <h1></h1>
    年龄上限:<el-input v-model="ches.maxage" style="width: 80%;"/><br>
    <h1></h1>
    项目价格:<el-input v-model="ches.price" style="width: 80%;"></el-input><br>
    <h1></h1>
    项目类别:<el-input v-model="ches.type" style="width: 80%;"></el-input><br>
    <h1></h1>
    所属分类:<el-input v-model="ches.classify" style="width: 80%;"></el-input><br>
    <h1></h1>
    项目说明:<el-input v-model="ches.item" style="width: 80%;"></el-input><br>
    <h1></h1>
    注意事项:<el-input v-model="ches.zysx" style="width: 80%;"></el-input><br>
    <h1></h1>
  
    <el-button @click="reset('motion'),up = false">取 消</el-button>
    <el-button type="primary" @click="up= false,update()" >修改</el-button>
  </el-form>
  </el-dialog>
  </div>
</template>

<script>
export default {
    data(){
        return{
            up:false,
            kk:false,
            itemName:"",
            list:[],
            total:10,
            currentPage4:1,
            pageSize:4,
            che:{itemname:"",sex:"",maxage:"",minage:"",type:"",price:"",item:"",zysx:"",classify:""},
            ches:{id:"",itemname:"",sex:"",maxage:"",minage:"",type:"",price:"",item:"",zysx:"",classify:""}
        }
    },
    methods:{
        queryAll(){
            this.axios.post("/tomcat/Z_queryChe",{num:this.pageSize,page:this.currentPage4,itemName:this.itemName})
            .then(s=>{
                this.total=s.data.total
                this.list=s.data.rows
            })
        },
        del(id){
          this.axios.get("/tomcat/Z_delChe?id="+id).then(s=>{
            if(s.data>0){
              this.$notify({
                    title: '成功',
                    message: '这是一条修改成功的提示消息',
                    type: 'success'
                  });
                  this.queryAll();
            }
          })
        },
        update(){
          this.axios.post("/tomcat/Z_upChe",{id:this.ches.id,itemname:this.ches.itemname,sex:this.ches.sex,
                maxage:this.ches.maxage,minage:this.ches.minage,type:this.ches.type,price:this.ches.price,
                item:this.ches.item,zysx:this.ches.zysx,classify:this.ches.classify}).then(s=>{
                  if(s.data>0){
                    this.$notify({
                    title: '成功',
                    message: '这是一条修改成功的提示消息',
                    type: 'success'
                  });
                  this.queryAll();
                  }
                })
        },
        queryId(id){
          this.axios.post("/tomcat/Z_byId",{id:id}).then(s=>{
            this.ches=s.data
          })
        },
        add(){
            this.axios.post("/tomcat/Z_addChe",{itemname:this.che.itemname,sex:this.che.sex,
                maxage:this.che.maxage,minage:this.che.minage,type:this.che.type,price:this.che.price,
                item:this.che.item,zysx:this.che.zysx,classify:this.che.classify}).then(s=>{
                    if(s.data>0){
                        this.$notify({
                        title: '成功',
                        message: '这是一条添加成功的提示消息',
                        type: 'success'
                        });
                        this.queryAll();
                        this.reset();
                    }
                })
        },
        handleSizeChange(val) {
            this.pageSize=val
            this.queryAll();
        
            },
            handleCurrentChange(val) {
                this.currentPage4=val
                this.queryAll();
            },
            reset(){
              this.che={}
            }
    },
    created(){
        this.queryAll();
    }
}
</script>

<style>

</style>